<?php
//  +----------------------------------------------------------------------
//  | Copyright (c) 2015-2025 http://www.hdphp.cn All rights reserved.
//  | Licensed ( http://www.hdphp.cn/licenses/ )
//  | Author: Jack <sophia2152@qq.com>
//  | 官方网址: http://www.hdphp.cn
//  | 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
//  | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
//  +----------------------------------------------------------------------
namespace app\controller\admin;

use app\Request;
use app\services\BaseServices;
use app\services\short\ShortServices;
use hdphp\services\wechat\MiniProgram;
use think\facade\Db;

class Test extends BaseServices
{
    /**
     * 短连接
     * @var ShortServices
     */
    protected $services;

    public function __construct(ShortServices $services)
    {
        $this->services = $services;
    }

    public function index()
    {
        $s = time();
        echo date('Y-m-d H:i:s',$s);
        echo '</br>-----------------------------------------------------------------------------------------------------</br>';
        // for ($k = 1; $k <= 3; $k++) {
        
        
            for ($i = 1; $i <= 100; $i++) {
                
                $row = MiniProgram::getLinkCode();
                if ($row['errcode'] === 0) {
                    $data['openlink'] = $row['url_link'];
                    $data['create_time'] = time();
                    Db::name('scheme')->insert($data);
                }
                
                // $row = MiniProgram::getSchemeCode();
                // if ($row['errcode'] === 0) {
                //     $data['openlink'] = $row['openlink'];
                //     $data['create_time'] = time();
                //     Db::name('scheme')->insert($data);
                //     //echo $i.'</br>';
                // }
            }
            
            
        echo '</br>-----------------------------------------------------------------------------------------------------</br>';
        $e = time();
        echo date('Y-m-d H:i:s',$e);
        echo '</br>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</br>';
        $num = $e - $s;
        echo $num;
            // sleep(2);
        echo '</br>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</br>';
        echo ("<script>setTimeout('window.location.reload()', 20000);</script>");
        // }
    }


    public function set_short(Request $request)
    {
        [$url] = $request->postMore([
            ['url', '']
        ], true);

        $res = $this->services->getSetShort($url);
        if ($res) {
            return app('json')->success($res);
        } else {
            return app('json')->fail('保存失败');
        }
    }


}